from time import sleep
from frp_page_object import login_page_frp, menu_page_frp, new_retail_order_page, new_samples_order_page
from ofc_page_object import toc_order_page, menu_page_ofc, login_page_ofc, delivery_notices_page


class BaseChainsService:
    def __init__(self):
        self.login_ofc_page = None
        self.order_number = None
        self.login_frp_page = login_page_frp.LoginPageFrp()
        self.menu_frp = menu_page_frp.MenuPage()
        self.menu_ofc = menu_page_ofc.MenuPage()
        self.toc_order = toc_order_page.TocOrderMngPage()
        self.login_ofc_page = login_page_ofc.LoginPageOfc()
        self.deliver_notices = delivery_notices_page.DeliveryNoticesPage()
        self.login_frp_page.open()

    # def input_form_header(self, ):
    #     pass
    #
    # def new_product(self):
    #     pass
    #
    # def audit(self):
    #     pass

    def login_frp(self):
        self.login_frp_page.login()
        return self.login_frp_page.check_login()

    def check_pre_order(self):
        # 此处应保存，提交
        self.login_frp_page.switch_to_window_by_title()
        self.login_ofc_page.open()
        self.login_ofc_page.login()
        self.login_ofc_page.check_login()
        self.menu_ofc.click_pre_oc_order()
        return self.toc_order.check_import_success(self.order_number, self.toc_order.loc_input_pre_order)

    def check_retail_channel_order(self):
        sleep(2)
        self.menu_ofc.click_retail_channel_order()
        return self.toc_order.check_import_success(self.order_number, self.toc_order.loc_input_retail_channel_orders)

    def check_retail_order(self):
        self.toc_order.wait_for_process()
        self.menu_ofc.click_retail_order()
        return self.toc_order.check_import_success(self.order_number, self.toc_order.loc_input_retail_orders)

    def check_cmp(self):
        self.toc_order.wait_for_generation()
        self.menu_ofc.click_cmp()
        return self.toc_order.check_import_success(self.order_number, self.toc_order.loc_input_retail_cmp)

    def check_distribution(self):
        return self.toc_order.check_distribution()

    def check_delivery(self):
        return self.toc_order.check_delivery()

    def check_notices(self):
        return self.toc_order.check_notices()

    def edit_delivery_notices(self):
        sleep(1)
        self.menu_ofc.click_delivery_notices()
        self.deliver_notices.desc_delivery_number()
        self.deliver_notices.click_edit()
        self.deliver_notices.click_transport_way('自行送货')
        self.deliver_notices.input_transport_describe('wwwwwwwwww')
        self.deliver_notices.input_address()
        self.deliver_notices.select_output_warehouses()
        self.deliver_notices.submit()
        sleep(5)
